package com.xspace.android.xafcommon.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by liuchen on 2016/11/11.
 */

public class ClassUtil {

    public static String WNX_MAIN_CLASS = "cn.xspace.wnx.activity.MainActivity";//微农信main

    public static String myWorkActivity = "cn.xspace.module.mywork.activity.MyWorkMainActivity";//我的工作 原生
    public static String myWorkFragment = "cn.xspace.module.mywork.fragment.MyWorkMainFragment";
    public static String WNX_CLASS = "cn.xspace.wnx.activity.WnxMainActivity";//微农信main
    public static String WNX_CLASS_FRAGMENT = "cn.xspace.wnx.fragment.WnxMainFragment";//微农信mainFragment
    //    public static String QAC_CLASS = "cn.xspace.module.qac.activity.QacHomeActivity";//农技员首页
    public static String QAC_CLASS = "cn.xspace.module.qac.activity.QacMainActivity";//农技员首页
    public static String LAW_CLASS = "cn.xspace.app.law.HomeLawTabHostAct";
    public static String APPSTORE_CLASS = "cn.xspace.module.appstore.activity.HomeAppStoreTabHostAct";//Appstore首页
    public static String NMG_CLASS = "cn.xspace.app.nmg.HomeNMGTabHostAct";
    public static String GQXX_CLASS = "cn.xspace.app.spdm.HomeSPDMTabHostAct";
    public static String XZL_CLASS = "cn.xspace.wnx.activity.WnxMainActivity";
    public static String SETTING_CLASS = "cn.xspace.module.other.activity.SettingAct";
    public static String SETTING_FRAGMENT = "cn.xspace.module.other.fragment.SettingFragment";
    public static String FUNCTIONCENTER_CLASS = "cn.xspace.module.appstore.activity.InstalledMainAct";
    public static String FUNCTIONCENTER_FRAGMENT = "cn.xspace.module.appstore.fragment.InstalledMainFragment";
    public static String AGINFOUNION_CENTER_CLASS = "cn.xspace.wnx.activity.WnxMainActivity";
    public static String BROWSER_CENTER_CLASS = "cn.xspace.module.other.activity.share.PlatformWebViewAct";
    public static String PLATFORM_WEBVIEWACT = "cn.xspace.module.other.activity.share.PlatformWebViewAct";
    public static String WNX_WEBVIEWACT = "cn.xspace.module.other.activity.share.WnxWebViewAct";
    public static String WNX_WEBVIEWFragment = "cn.xspace.module.other.fragment.WnxWebViewFragment";
    public static String LOGIN_CLASS = "cn.xspace.module.other.activity.LoginAct";
    public static String USERINFO_ACTIVITY = "cn.xspace.module.other.activity.UserInfoAct";
    public static String DCLOUD_WEBVIEW = "cn.xspace.module.mywork.activity.MyCordovaWebViewAct";
    public static String WORK_SIGN_ACTIVITY = "cn.xspace.module.mywork.activity.MyWorkSignActivity";
    public static String ServiceObjActivity = "cn.xspace.wnx.activity.ServiceObjActivity";//服务对象
    public static String CQFYRecordListActivity = "cn.xspace.module.form.activity.CQFYRecordListActivity";//春秋防疫

    public static String WNX_SERVICE = "cn.xspace.wnx.service.WnxService";
    public static String HuanXinHelper = "cn.xspace.wnx.util.HuanXinHelper";
    public static String OrganizationInfoActivity = "cn.xspace.wnx.activity.OrganizationInfoActivity";
    public static String PlaceSetAct = "cn.xspace.module.other.activity.PlaceSetAct";
    public static String ACTIVITY_WORKLOG = "cn.xspace.module.mywork.activity.WorkLogMainActivity";
    public static String INDEX_CLASS = "cn.xspace.app.activity.IndexActivity";
    public static String INDEX_FRAGMENT = "cn.xspace.app.fragment.IndexFragment";
    public static String MANAGER_FAVORITOR_WEB = "cn.xspace.module.other.activity.ManagerFavoritorWeb";
    public static String MY_FAVORITE_MANAGER_ACTIVITY = "cn.xspace.module.other.activity.MyFavoriteManagerActivity";
    public static String WEBVIEW_FRAGMENT = "cn.xspace.module.other.fragment.PlatformWebViewFragment";
    public static String DCLOUD_WEBVIEW_FRAGMENT = "com.ctnq.dcloud.dcloud.DcloudWebviewFragment";
    public static String DCLOUD_WEBVIEW_ACTIVITY = "cn.xspace.app.activity.DcloudWebViewActivity";
    public static String NOTIFIER_CLASS = "cn.xspace.wnx.util.Notifier";
    public static String ExWebAct = "cn.xspace.module.other.activity.share.ExWebAct";
    //问答广场
    public static String qacSquareActivity = "cn.xspace.module.qac.activity.SquareAct";
    public static String qacSquareFragment = "cn.xspace.module.qac.fragment.SquareFragment";
    //工作日志
    public static String workLogActivity = "cn.xspace.module.mywork.activity.WorkLogMainActivity";
    public static String workLogFragment = "cn.xspace.module.mywork.fragment.WorkLogMainFragment";
    public static String MyScheduleActivity = "cn.xspace.module.mywork.activity.MyScheduleActivity";
    public static String FarmerDeclareActivity = "cn.xspace.module.mywork.activity.FarmerDeclareActivity";
    public static String workTotoFragment = "cn.xspace.module.mywork.fragment.MyWorkToDoFragment";
    //日志详情
    public static String WorkLogDetailActivity = "cn.xspace.module.mywork.activity.WorkLogDetailActivity";
    //工作日志相关服务
    public static String OfflineDataService = "cn.xspace.module.mywork.service.OfflineDataService";
    public static String LogCommitService = "cn.xspace.module.mywork.service.LogTimerCommitService";
    public static String VideoMonitorActivity = "cn.xspace.module.mywork.activity.MyServiceObjActivity";
    public static String AddWorkLogActivity = "cn.xspace.module.mywork.activity.AddWorkLogActivity";
    //我的收藏-个人中心
    public static String MyFavoriteActivity = "cn.xspace.module.other.activity.MyFavoriteActivity";
    //通知公告
    public static String NoticeOrWNXListActivity = "cn.xspace.wnx.activity.NoticeOrWNXListActivity";
    //在线农技员
    public static String CommonTransferActivity = "cn.xspace.module.qac.activity.CommonTransferActivity"; //问题广场
    //离线数据
    public static String offlineDataActivity = "cn.xspace.module.mywork.activity.OfflineDataActivity";
    public static String offlineDataFragment = "cn.xspace.module.mywork.fragment.OfflineDataFragment";

    public static String WorkBenchFragment = "cn.xspace.app.fragment.MyWorkIndexFragment";
    public static String WorkBenchActivity = "cn.xspace.app.activity.WorkIndexActivity";

    //筛选界面
    public static String WorkItemFilterActivity = "cn.xspace.module.mywork.activity.WorkItemFilterActivity";
    //聊天界面
    public static String ChatActivity = "cn.xspace.wnx.activity.ChatActivity";

    public static String WNXDBManager = "cn.xspace.wnx.db.WNXDBManager";

    public static String LogCommitActivity = "cn.xspace.module.mywork.activity.LogCommitActivity";

    public static String QAC_CHAT_ACTIVITY = "cn.xspace.module.qac.activity.QacChatConversationActivity";

    public static Class getClassByName(String className) {
        Class clz = null;
        try {
            clz = Class.forName(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return clz;
    }

    public static Object getClassField(String className, String filedName) {
        Class clz = getClassByName(className);
        Object obj = null;
        if (clz != null) {
            try {
                Field declaredField = clz.getDeclaredField(filedName);
                declaredField.setAccessible(true);
                obj = declaredField.get(null);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }

    public static Object getMethod(String className, String methodName) {
        LogUtil.d("getMethod", "getMethod() called with: className = [" + className + "], methodName = [" +
                methodName + "]");
        Class clz = getClassByName(className);
        Object obj = null;
        if (clz != null) {
            try {
                Method newInstance = clz.getMethod(methodName);
                obj = newInstance.invoke(null);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }

    //Notifier.getInstance().reset();
    public static Object getOtherMethod(Object obj, String methodName) {
//        Object obj = getMethod("cn.xspace.demp.util.DemoUtil", "getInstance");
        LogUtil.d("obj " + obj + " method " + methodName);
        if (obj == null) {
            return null;
        }
        Object obj2 = null;
        try {
            Method method = obj.getClass().getMethod(methodName);
            obj2 = method.invoke(obj);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return obj2;
    }

    public static Object getOtherMethodArgs(Object obj, String methodName, Class[] classes, Object[] objects) {
//        Object obj = getMethod("cn.xspace.demp.util.DemoUtil", "getInstance");
        LogUtil.d("obj " + obj + " method " + methodName);
        if (obj == null) {
            return null;
        }
        Object obj2 = null;
        try {
            Method method = obj.getClass().getDeclaredMethod(methodName, classes);
            obj2 = method.invoke(obj, objects);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return obj2;
    }


//    Class clz = ClassUtil.getClassByName(ClassUtil.INDEX_FRAGMENT);
//    Object obj = null;
//    if (clz != null) {
//        try {
//            Method newInstance = clz.getMethod("newInstance");
//            obj = newInstance.invoke(null);
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        } catch (InvocationTargetException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
//    }
}
